﻿using ComLib.ComFun;
using ComLib.ConfigService;
using LogLib;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Ports;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace YSLPages
{
    public class YSLHighCaptureLTOption : IniConfigBase
    {
        public YSLHighCaptureLTOption()
            : base()
        {
        }

        public override string ConfigDirectory
        {
            get
            {
                string directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().CodeBase);
                directory = directory.Substring(6);
                return directory;
            }
        }

        /// <summary>
        /// 传感器连接的串口号
        /// </summary>
        private string highCaptureCameraName = "COM8";
        public string HighCaptureCameraName
        {
            get { return highCaptureCameraName; }
            set { highCaptureCameraName = value; }
        }


        public override bool Save()
        {
            base.Save();
            SaveField("HighCaptureCameraName", highCaptureCameraName);
           
            return true;
        }

        public override bool Load()
        {
            base.Load();
            try
            {
                highCaptureCameraName = LoadStringValue("HighCaptureCameraName");
            }
            catch (Exception ex)
            {
                ErrorMessage = string.Format("配置文件{0}加载错误:\n\t{1}", ConfigFilePath, ex.Message);
                Log.WriteException(ex.ToString());
                return false;
            }
            return true;
        }

        public override string ToString()
        {
            StringBuilder builder = new StringBuilder("高拍选项配置: ");
            FillFieldValueStringDelegate FillString =
                (string field, object val) =>
                {
                    builder.Append("[");
                    builder.Append(field);
                    builder.Append("]: ");
                    builder.Append(val.ToString() + "; ");
                };
            FillString("高拍摄像头名称", highCaptureCameraName);
            
            return builder.ToString();
        }
    }
}
